@extends('layouts.public')

@section('bodyattr')class="gray-bg"@endsection

@section('body')
    <div class="wrapper wrapper-content">
        <div class="row m-b">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="{{route('admin.good.goods')}}">商品列表</a></li>
                        <li><a href="{{route('admin.good.goods.add')}}">新增</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <form role="form" class="form-inline" method="get">
                            <div class="form-group">
                                <label class="sr-only">商品搜索</label>
                                <input type="text" name="title" placeholder="商品名称" class="form-control"
                                       value="{{request('title')}}">
                            </div>
                            &nbsp;&nbsp;
                            <div class="form-group">
                                <input placeholder="请选择发布时间范围" class="form-control" id="created_at" type="text"
                                       name="created_at" value="{{request('created_at')}}" style="width: 200px;"
                                       autocomplete="off">
                            </div>
                            <button type="submit" class="btn btn-primary">搜索</button>
                            <button type="button" class="btn btn-white"
                                    onclick="location.href='{{route('admin.good.goods')}}'">重置
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                            <thead>
                            <tr role="row">
                                <th>商品ID</th>
                                <th>商品标题</th>
                                <th>商品图片</th>
                                <th>商品浏览数</th>
                                <th>商品评论数</th>
                                <th class="sorting" orderby="created_at">创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            @foreach($goods as $user)
                                <tr class="gradeA">
                                    <td>{{$user['id']}}</td>
                                    <td>{{$user['title']}}</td>
                                    <td>
                                        @foreach(explode(',',$user['default_img']) as $g)<img src="{{$g}}"
                                                                                              alt=""> @endforeach
                                    </td>
                                    <td>{{$user['views']}}</td>
                                    <td>{{$user['comments']}}</td>
                                    <td>{{$user['created_at']}}</td>

                                    <td>

                                        <a href="{{route('admin.good.goods.comment',[$user->id])}}">评论</a>|
                                        @if($user['status']=='1')
                                            <a class="ajaxBtn " href="javascript:void(0);"
                                               uri="{{route('admin.good.goods.change',[$user->id])}}" msg="请确认是否下架商品？">下架</a>
                                            |
                                        @endif
                                        @if($user['status']=='2')
                                            <a class="ajaxBtn " href="javascript:void(0);"
                                               uri="{{route('admin.good.goods.change',[$user->id])}}" msg="请确认是否上架商品？">上架</a>
                                            |
                                        @endif
                                        @if($user['is_recommend']=='0')
                                            <a class="ajaxBtn" href="javascript:void(0);"
                                               uri="{{route('admin.good.goods.recommend',[$user->id])}}"
                                               msg="请确认是否推荐该商品到首页？">设置推荐</a>|
                                        @endif
                                        @if($user['is_recommend']=='1')
                                            <a class="ajaxBtn" href="javascript:void(0);"
                                               uri="{{route('admin.good.goods.recommend',[$user->id])}}"
                                               msg="请确认是否取消推荐该商品到首页？">取消推荐</a>|
                                        @endif
                                        <a href="{{route('admin.good.goods.edit',[$user->id])}}">编辑</a>
                                        | <a class="ajaxBtn btn btn-danger" href="javascript:void(0);"
                                             uri="{{route('admin.good.goods.delete',[$user->id])}}"
                                             msg="商品一旦删除，不可恢复，请确认是否删除该商品？">删除</a>
                                    </td>
                                </tr>
                            @endforeach
                        </table>
                        <div class="row">
                            <div class="col-sm-12">
                                <div>共 {{ $goods->total() }} 条记录</div>
                                {!! $goods->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script type="text/javascript" src="{{cdn('js/plugins/laydate/laydate.js')}}"></script>
    <script type="text/javascript">
        laydate.render({
            elem: '#created_at',
            range: true,
            max: 0
        });
    </script>
@endsection
